/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package CareerService.UserDAO;

import CareerService.Entitybeans.Users;
import java.util.*;
import javax.ejb.Stateless;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

/**
 *
 * @author Administrator
 */
@Stateless
public class LoginBean implements LoginLocal {
    @PersistenceContext protected EntityManager em;

    public Users login(String username, String password) {
        Query query =em.createQuery("select DISTINCT u from Users where u.username=:name and u.userPassword=:pwd");
        query.setParameter("name",username);
        query.setParameter("pwd", password);

        List result =query.getResultList();
        Iterator iterator=result.iterator();

        while (iterator.hasNext()){
            return (Users)iterator.next();
        }

        return null;

    }
    
    // Add business logic below. (Right-click in editor and choose
    // "Insert Code > Add Business Method" or "Web Service > Add Operation")
 
}
